package cn.com.header.zbpk.base.service.impl;

import cn.com.header.zbpk.base.entity.Section;
import cn.com.header.zbpk.base.mapper.ISectionMapper;
import cn.com.header.zbpk.base.service.ISectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

/**
 * @author Yuanyifeng
 * @date 2017-11-21
 * @time 17:39
 */
@Service
public class SectionServiceImpl implements ISectionService{
    @Autowired
    private ISectionMapper iSectionMapper;

    @Override
    public List<Section> loads(Section section, boolean nameLikeMode, Set<String> fields) {
        return iSectionMapper.loads(section, nameLikeMode, fields);
    }

    @Override
    public Optional<Section> loadBy(Long id, Set<String> fields) {
        Section section = new Section(id);
        List<Section> sections = iSectionMapper.loads(section, false, fields);
        if (Objects.isNull(sections) && sections.isEmpty()){
            return Optional.empty();
        }
        return Optional.of(sections.get(0));
    }
}
